package com.bsj.power.sdk.config.hksdk.configuration;

import com.bsj.power.sdk.config.hksdk.HCNetSDK;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;

import static com.bsj.power.sdk.config.hksdk.HKSDKClientManage.hCNetSDK;

/**
 * @author yinhao
 * @version 1.0
 * @description 设备参数获取与配置
 * @date 2024/8/30
 */
@Slf4j
public class Parmcfg {

    //获取设备的基本参数
    public static void  getCfg(int iUserID) {
        HCNetSDK.NET_DVR_DEVICECFG_V40 m_strDeviceCfg = new HCNetSDK.NET_DVR_DEVICECFG_V40();
        m_strDeviceCfg.dwSize = m_strDeviceCfg.size();
        m_strDeviceCfg.write();
        Pointer pStrDeviceCfg = m_strDeviceCfg.getPointer();
        IntByReference pInt = new IntByReference(0);
        boolean b_GetCfg = hCNetSDK.NET_DVR_GetDVRConfig(iUserID, HCNetSDK.NET_DVR_GET_DEVICECFG_V40,
                0Xffffffff, pStrDeviceCfg, m_strDeviceCfg.dwSize, pInt);
        if (b_GetCfg == false) {
            System.out.println("获取参数失败  错误码：" + hCNetSDK.NET_DVR_GetLastError());
        }
        System.out.println("获取参数成功");
        m_strDeviceCfg.read();
        System.out.println("设备名称:" + new String(m_strDeviceCfg.sDVRName).trim() + "设备序列号：" + new String(m_strDeviceCfg.sSerialNumber));
        System.out.println("模拟通道个数" + m_strDeviceCfg.byChanNum);
        parseVersion(m_strDeviceCfg.dwSoftwareVersion);
        parseBuildTime(m_strDeviceCfg.dwSoftwareBuildDate);
        parseDSPBuildDate(m_strDeviceCfg.dwDSPSoftwareBuildDate);
    }


    public  static void parseBuildTime(int buildTime) {
        int year =( (buildTime & 0XFF << 16) >> 16)+2000;
        int month = (buildTime & 0XFF << 8) >> 8 ;
        int data = buildTime & 0xFF;
        System.out.println("Build:"+year+"."+month+"."+data);



    }

    public  static void parseDSPBuildDate(int DSPBuildDate ) {
        int year =( (DSPBuildDate & 0XFF << 16) >> 16)+2000;
        int month = (DSPBuildDate & 0XFF << 8) >> 8 ;
        int data = DSPBuildDate & 0xFF;
        System.out.println("DSPBuildDate:"+year+"."+month+"."+data);



    }

    //设备版本解析
    public static void parseVersion(int version) {
        int firstVersion = (version & 0XFF << 24) >> 24;
        int secondVersion = (version & 0XFF << 16) >> 16 ;
        int lowVersion = version & 0XFF;

        System.out.println("firstVersion:"+ firstVersion);
        System.out.println("secondVersion:"+ secondVersion);
        System.out.println("lowVersion:"+ lowVersion);
    }

}
